﻿using System;
using System.Linq;

class RectangularMatrixMaxSum
{
    static void Main()
    {
        int matrixRows = int.Parse(Console.ReadLine());
        int matrixColumns = int.Parse(Console.ReadLine());
        int[,] matrix = new int[matrixRows, matrixColumns];
        int sizeOfSquare = 3;
        int maxSum = int.MinValue;
        Random randomNumber = new Random();
        //int someNumber = 1;
        //int maxRow = -1;
        //int maxCol = -1;

        //fill in the matrix
        for (int row = 0; row < matrix.GetLength(0); row++)
        {
            for (int col = 0; col < matrix.GetLength(1); col++)
            {
                matrix[row, col] = randomNumber.Next(1,10);
                //someNumber++;
                //matrix[row, col] = someNumber;

            }
        }

        //print the matrix
        //for (int row = 0; row < matrix.GetLength(0); row++)
        //{
        //    for (int col = 0; col < matrix.GetLength(1); col++)
        //    {
        //        Console.Write("{0}\t", matrix[row, col]);

        //    }
        //    Console.WriteLine();

        //}


        //find the biggest sum of 3x3 square 
        for (int row = 0; row < matrix.GetLength(0) - (sizeOfSquare-1); row++)
        {
            for (int column = 0; column < matrix.GetLength(1) - (sizeOfSquare-1); column++)
            {
                // left corner of the square has current row and column
                int tempSum = 0;
                for (int rowSquare = row; rowSquare < row + sizeOfSquare; rowSquare++)
                {
                    for (int colSquare = column; colSquare < column + sizeOfSquare; colSquare++)
                    {
                        tempSum += matrix[rowSquare, colSquare];

                    }
                }

                if (tempSum > maxSum)
                {
                    maxSum = tempSum;
                    //maxCol = column;
                    //maxRow = row;
                    
                }
            }
        }

        //Console.WriteLine("maximal sum: {0}\nmaximal row{1}\nmaximal column: {2}\n",maxSum, maxRow, maxCol);
        Console.WriteLine("maximal sum: {0}", maxSum);
    }
}

